﻿using SqlExecHelper.Interface;
using SqlExecHelper.Join;
using SqlExecHelper.SqlValue;

namespace SqlExecHelper
{
        public class SqlBasicClass : SqlBasicDAL, System.IDisposable
        {
                private readonly string _TableName = null;
                public SqlBasicClass(string table)
                {
                        this._TableName = table;
                }
                public SqlBasicClass(string table, string conName) : base(conName)
                {
                        this._TableName = table;
                }

                protected IBatchMerge BatchMerge(int row, int col)
                {
                        return SqlExecTool.BatchMerge(this._TableName, this.MyDAL, row, col);
                }
                protected IBatchMerge BatchMerge(string table, int row, int col)
                {
                        return SqlExecTool.BatchMerge(table, this.MyDAL, row, col);
                }

                #region 连表查询

                protected T JoinScalar<T>(string table, string column, SqlFuncType funcType, params ISqlWhere[] where) where T : struct
                {
                        return SqlExecTool.JoinScalar<T>(this._TableName, table, this.MyDAL, column, funcType, where);
                }
                protected T[] JoinQuery<T>(string table, params ISqlWhere[] where)
                {
                        return SqlExecTool.JoinQuery<T>(this._TableName, table, this.MyDAL, where);
                }
                protected T[] JoinQuery<T>(string table, string column, params ISqlWhere[] where)
                {
                        JoinColumn col;
                        if (column.IndexOf(".") != -1)
                        {
                                string[] str = column.Split('.');
                                col = new JoinColumn
                                {
                                        Table = str[0],
                                        Column = str[1]
                                };
                        }
                        else
                        {
                                col = new JoinColumn
                                {
                                        Column = column
                                };
                        }
                        return SqlExecTool.JoinQuery<T>(this._TableName, table, this.MyDAL, col, where);
                }

                protected T[] JoinQuery<T>(string table, IOrderBy[] orderby, params ISqlWhere[] where)
                {
                        return SqlExecTool.JoinQuery<T>(this._TableName, table, this.MyDAL, orderby, where);
                }
                protected T[] JoinQuery<T>(string table, IOrderBy[] orderBy, int index, int size, out long count, params ISqlWhere[] where)
                {
                        return SqlExecTool.JoinQuery<T>(this._TableName, table, this.MyDAL, orderBy, index, size, out count, where);
                }
                protected T[] JoinQuery<T>(string table, string orderBy, int index, int size, out long count, params ISqlWhere[] where)
                {
                        return SqlExecTool.JoinQuery<T>(this._TableName, table, this.MyDAL, new IOrderBy[] {
                                new SqlOrderBy(this._TableName,orderBy,true)
                        }, index, size, out count, where);
                }
                protected T[] JoinQuery<T>(string table, string orderBy, int index, int size, string column, params ISqlWhere[] where)
                {
                        return SqlExecTool.JoinQuery<T>(this._TableName, table, this.MyDAL, new IOrderBy[] {
                                new SqlOrderBy(this._TableName,orderBy,true)
                        }, index, size, new JoinColumn
                        {
                                Column = column,
                                Table = this._TableName,
                        }, where);
                }
                protected T[] JoinQuery<T>(string table, IOrderBy[] orderBy, int index, int size, params ISqlWhere[] where)
                {
                        return SqlExecTool.JoinQuery<T>(this._TableName, table, this.MyDAL, orderBy, index, size, where);
                }
                #endregion

                #region "插入"

                protected IInsertTable InsertTable(int row, int col)
                {
                        return SqlExecTool.InsertTable(this._TableName, this.MyDAL, row, col);
                }
                protected IInsertTable InsertTable(string tableName, int row, int col)
                {
                        return SqlExecTool.InsertTable(tableName, this.MyDAL, row, col);
                }

                protected IBatchInsert BatchInsert()
                {
                        return SqlExecTool.BatchInsert(this._TableName, this.MyDAL);
                }
                protected IInsertTable InsertTable()
                {
                        return SqlExecTool.InsertTable(this._TableName, this.MyDAL);
                }
                protected void Insert<T>(T[] adds) where T : class
                {
                        SqlExecTool.Insert(this._TableName, this.MyDAL, adds);
                }
                protected void Insert<T>(string tableName, T[] adds) where T : class
                {
                        SqlExecTool.Insert(tableName, this.MyDAL, adds);
                }
                protected Result[] Insert<T, Result>(T[] adds) where T : class
                {
                        return SqlExecTool.Insert<T, Result>(this._TableName, this.MyDAL, adds);
                }
                protected Result[] InsertOutColumn<T, Result>(T[] adds, string column) where T : class
                {
                        return SqlExecTool.InsertOutColumn<T, Result>(this._TableName, this.MyDAL, adds, column);
                }
                protected void Insert<T>(T data) where T : class
                {
                        SqlExecTool.Insert(this._TableName, this.MyDAL, data);
                }
                protected Result InsertOutRow<T, Result>(T data) where T : class
                {
                        return SqlExecTool.InsertOutRow<T, Result>(this._TableName, this.MyDAL, data);
                }
                protected Result InsertOutColumn<T, Result>(T data, string column) where T : class
                {
                        return SqlExecTool.InsertOutColumn<T, Result>(this._TableName, this.MyDAL, data, column);
                }
                protected void Insert<T>(T data, out long id) where T : class
                {
                        SqlExecTool.Insert(this._TableName, this.MyDAL, data, out id);
                }
                protected void Insert(IInsertSqlValue[] column, out long id)
                {
                        SqlExecTool.Insert(this._TableName, this.MyDAL, column, out id);
                }
                protected void Insert(IInsertSqlValue[] column, out int id)
                {
                        SqlExecTool.Insert(this._TableName, this.MyDAL, column, out id);
                }
                protected void Insert<T>(T data, out int id) where T : class
                {
                        SqlExecTool.Insert(this._TableName, this.MyDAL, data, out id);
                }
                #endregion

                #region 删除数据

                protected IBatchDrop BatchDrop(int row, int col)
                {
                        return SqlExecTool.BatchDrop(this._TableName, this.MyDAL, row, col);
                }
                protected bool Drop<T>(string column, T[] datas, params ISqlWhere[] param)
                {
                        if (datas.Length == 1)
                        {
                                return SqlExecTool.Drop(this._TableName, this.MyDAL, column, datas[0], param);
                        }
                        return SqlExecTool.BatchDrop(this._TableName, this.MyDAL, column, datas, param);
                }
                protected Result[] BatchDrop<T, Result>(string column, T[] datas, params ISqlWhere[] param)
                {
                        return SqlExecTool.BatchDrop<T, Result>(this._TableName, this.MyDAL, column, datas, param);
                }
                protected Result[] BatchDrop<T, Result>(string column, T[] datas, string returnCol, params ISqlWhere[] param)
                {
                        return SqlExecTool.BatchDrop<T, Result>(this._TableName, this.MyDAL, column, datas, returnCol, param);
                }
                protected bool Drop(ISqlWhere[] where)
                {
                        return SqlExecTool.Drop(this._TableName, this.MyDAL, where);
                }
                protected bool Drop(string table, ISqlWhere[] where)
                {
                        return SqlExecTool.Drop(table, this.MyDAL, where);
                }
                protected bool Drop<T>(string column, T data)
                {
                        return SqlExecTool.Drop(this._TableName, this.MyDAL, column, data);
                }
                protected Result DropOutRow<T, Result>(string column, T data)
                {
                        return SqlExecTool.DropOutRow<T, Result>(this._TableName, this.MyDAL, column, data);
                }
                protected Result DropOutScalar<T, Result>(string column, T data, string rColumn)
                {
                        return SqlExecTool.DropOutScalar<T, Result>(this._TableName, this.MyDAL, column, data, rColumn);
                }
                protected Result[] Drop<T, Result>(string column, T data, string returnColumn)
                {
                        return SqlExecTool.Drop<T, Result>(this._TableName, this.MyDAL, column, data, returnColumn);
                }
                protected T DropOutRow<T>(ISqlWhere[] where)
                {
                        return SqlExecTool.DropOutRow<T>(this._TableName, this.MyDAL, where);
                }
                protected T[] Drop<T>(params ISqlWhere[] where)
                {
                        return SqlExecTool.Drop<T>(this._TableName, this.MyDAL, where);
                }
                protected T DropOutScalar<T>(string rColumn, ISqlWhere[] where)
                {
                        return SqlExecTool.DropOutScalar<T>(this._TableName, this.MyDAL, rColumn, where);
                }
                protected T[] DropOutColumn<T>(string rColumn, ISqlWhere[] where)
                {
                        return SqlExecTool.DropOutColumn<T>(this._TableName, this.MyDAL, rColumn, where);
                }
                #endregion

                #region 修改


                protected IBatchUpdate BatchUpdate(int row, int col)
                {
                        return SqlExecTool.BatchUpdate(this._TableName, this.MyDAL, row, col);
                }

                protected bool Update(ISqlSetColumn[] columns, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update(this._TableName, this.MyDAL, columns, where);
                }
                protected bool Update(string table, ISqlSetColumn[] columns, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update(this._TableName, table, this.MyDAL, columns, where);
                }

                protected bool Update<T>(ISqlSetColumn[] columns, string column, T[] vals, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update(this._TableName, this.MyDAL, columns, column, vals, where);
                }
                protected Result[] Update<T, Result>(ISqlSetColumn[] columns, SqlEventPrefix prefix, string column, T[] vals, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<T, Result>(this._TableName, this.MyDAL, columns, prefix, column, vals, where);
                }
                protected Result[] Update<T, Result>(ISqlSetColumn[] columns, SqlEventPrefix prefix, string rcolumn, string column, T[] vals, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<T, Result>(this._TableName, this.MyDAL, columns, rcolumn, prefix, column, vals, where);
                }
                protected Result[] Update<T, Result>(ISqlSetColumn[] columns, string column, T[] vals, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<T, Result>(this._TableName, this.MyDAL, columns, SqlEventPrefix.deleted, column, vals, where);
                }
                protected bool Update<T>(ISqlSetColumn[] columns, string column, T val)
                {
                        return SqlExecTool.Update(this._TableName, this.MyDAL, columns, column, val);
                }
                protected Result UpdateOutRow<Result>(ISqlSetColumn[] columns, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutRow<Result>(this._TableName, this.MyDAL, columns, where);
                }
                protected Result UpdateOutRow<Result>(string table, ISqlSetColumn[] columns, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutRow<Result>(table, this.MyDAL, columns, where);
                }
                protected Result UpdateOutRow<Result>(string table, ISqlSetColumn[] columns, SqlEventPrefix prefix, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutRow<Result>(table, this.MyDAL, columns, prefix, where);
                }
                protected Result UpdateOutRow<Result>(ISqlSetColumn[] columns, SqlEventPrefix prefix, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutRow<Result>(this._TableName, this.MyDAL, columns, prefix, where);
                }
                protected Result UpdateOutScalar<Result>(ISqlSetColumn[] columns, string rColumn, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutScalar<Result>(this._TableName, this.MyDAL, columns, rColumn, where);
                }
                protected Result UpdateOutScalar<Result>(string table, ISqlSetColumn[] columns, string rColumn, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutScalar<Result>(table, this.MyDAL, columns, rColumn, where);
                }
                protected Result UpdateOutScalar<Result>(string table, ISqlSetColumn[] columns, string rColumn, SqlEventPrefix prefix, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutScalar<Result>(table, this.MyDAL, columns, rColumn, prefix, where);
                }
                protected Result UpdateOutScalar<Result>(ISqlSetColumn[] columns, string column, SqlEventPrefix prefix, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutScalar<Result>(this._TableName, this.MyDAL, columns, column, prefix, where);
                }

                protected bool Update<T>(T data, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update(this._TableName, this.MyDAL, data, where);
                }
                protected bool Update<T, Val>(T data, string column, Val val)
                {
                        return SqlExecTool.Update(this._TableName, this.MyDAL, data, column, val);
                }
                protected bool Update<T, Val>(T data, string column, Val[] val)
                {
                        return SqlExecTool.Update<T, Val>(this._TableName, this.MyDAL, data, column, val);
                }

                protected Result UpdateOutRow<T, Result>(T data, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutRow<T, Result>(this._TableName, this.MyDAL, data, where);
                }
                protected Result UpdateOutRow<T, Result>(T data, SqlEventPrefix prefix, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutRow<T, Result>(this._TableName, this.MyDAL, data, prefix, where);
                }

                protected Result UpdateOutScalar<T, Result>(T data, string rColumn, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutScalar<T, Result>(this._TableName, this.MyDAL, data, rColumn, where);
                }
                protected Result UpdateOutScalar<T, Result>(T data, string rColumn, SqlEventPrefix prefix, params ISqlWhere[] where)
                {
                        return SqlExecTool.UpdateOutScalar<T, Result>(this._TableName, this.MyDAL, data, rColumn, prefix, where);
                }

                protected Result[] Update<Result>(ISqlSetColumn[] columns, SqlEventPrefix prefix, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<Result>(this._TableName, this.MyDAL, columns, prefix, where);
                }
                protected Result[] Update<Result>(ISqlSetColumn[] columns, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<Result>(this._TableName, this.MyDAL, columns, where);
                }
                protected Result[] Update<Result>(ISqlSetColumn[] columns, string rColumn, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<Result>(this._TableName, this.MyDAL, columns, rColumn, SqlEventPrefix.deleted, where);
                }
                protected Result[] Update<Result>(ISqlSetColumn[] columns, string column, SqlEventPrefix prefix, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<Result>(this._TableName, this.MyDAL, columns, column, prefix, where);
                }

                protected Result[] Update<T, Result>(T data, SqlEventPrefix prefix, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<T, Result>(this._TableName, this.MyDAL, data, prefix, where);
                }
                protected Result[] Update<T, Result>(T data, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<T, Result>(this._TableName, this.MyDAL, data, where);
                }

                protected Result[] Update<T, Result>(T data, string rColumn, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<T, Result>(this._TableName, this.MyDAL, data, rColumn, where);
                }
                protected Result[] Update<T, Result>(T data, string rColumn, SqlEventPrefix prefix, params ISqlWhere[] where)
                {
                        return SqlExecTool.Update<T, Result>(this._TableName, this.MyDAL, data, rColumn, prefix, where);
                }
                #endregion

                #region 批量查询
                protected IBatchQuery BatchQuery(int row, int col)
                {
                        return SqlExecTool.BatchQuery(this._TableName, this.MyDAL, row, col);
                }
                #endregion

                #region 表分页查询
                protected T[] QueryTable<T>(string table, string orderBy, int index, int size, out long count, params ISqlWhere[] where)
                {
                        return SqlExecTool.Query<T>(table, this.MyDAL, orderBy, index, size, out count, where);
                }
                #endregion

                #region 分页查询
                protected T[] Query<T>(string orderBy, int index, int size, out long count, params ISqlWhere[] where)
                {
                        return SqlExecTool.Query<T>(this._TableName, this.MyDAL, orderBy, index, size, out count, where);
                }
                protected T[] Query<T>(string column, string orderBy, int index, int size, out long count, params ISqlWhere[] where)
                {
                        return SqlExecTool.Query<T>(this._TableName, this.MyDAL, column, orderBy, index, size, out count, where);
                }

                protected T[] Query<T>(string column, string orderBy, int index, int size, params ISqlWhere[] where)
                {
                        return SqlExecTool.Query<T>(this._TableName, this.MyDAL, column, orderBy, index, size, where);
                }
                protected T[] Query<T>(string orderBy, int index, int size, params ISqlWhere[] where)
                {
                        return SqlExecTool.Query<T>(this._TableName, this.MyDAL, orderBy, index, size, where);
                }
                #endregion

                #region 查询列表

                protected Result[] GetOutColumn<T, Result>(string column, T[] ids, string rColumn, params ISqlWhere[] where)
                {
                        return SqlExecTool.GetOutColumn<T, Result>(this._TableName, this.MyDAL, column, ids, rColumn, where);
                }
                protected Result[] GetOutColumn<T, Result>(string column, T val, string rColumn, params ISqlWhere[] where)
                {
                        return SqlExecTool.GetOutColumn<T, Result>(this._TableName, this.MyDAL, rColumn, column, val, where);
                }
                protected Result[] Get<T, Result>(string column, T[] ids, params ISqlWhere[] where)
                {
                        return SqlExecTool.Get<T, Result>(this._TableName, this.MyDAL, column, ids, where);
                }


                protected Result[] Get<T, Result>(string column, T data, params ISqlWhere[] where)
                {
                        return SqlExecTool.Get<T, Result>(this._TableName, this.MyDAL, column, data, where);
                }
                protected T[] Get<T>(params ISqlWhere[] where)
                {
                        return SqlExecTool.Get<T>(this._TableName, this.MyDAL, where);
                }
                protected T[] Get<T>(string orderBy, params ISqlWhere[] where)
                {
                        return SqlExecTool.Get<T>(this._TableName, this.MyDAL, orderBy, where);
                }
                protected T[] GetOutColumn<T>(string column, params ISqlWhere[] where)
                {
                        return SqlExecTool.GetOutColumn<T>(this._TableName, this.MyDAL, column, where);
                }
                protected T[] GetOutColumn<T>(string column, string orderBy, params ISqlWhere[] where)
                {
                        return SqlExecTool.GetOutColumn<T>(this._TableName, this.MyDAL, column, orderBy, where);
                }
                #endregion

                #region TOP查询(select top)
                protected T[] GetTop<T>(int top, params ISqlWhere[] where)
                {
                        return SqlExecTool.GetTop<T>(this._TableName, this.MyDAL, top, where);
                }
                protected T[] GetTop<T>(int top, string orderBy, params ISqlWhere[] where)
                {
                        return SqlExecTool.GetTop<T>(this._TableName, this.MyDAL, top, orderBy, where);
                }
                protected T[] GetTop<T>(string column, int top, params ISqlWhere[] where)
                {
                        return SqlExecTool.GetTop<T>(this._TableName, this.MyDAL, column, top, where);
                }
                protected T[] GetTop<T>(int top, string column, string orderBy, params ISqlWhere[] where)
                {
                        return SqlExecTool.GetTop<T>(this._TableName, this.MyDAL, top, column, orderBy, where);
                }
                #endregion

                #region 查询单行(GetRow)

                protected T GetRow<T>(params ISqlWhere[] where)
                {
                        return SqlExecTool.GetRow<T>(this._TableName, this.MyDAL, where);
                }
                protected Result GetRow<val, Result>(string column, val value)
                {
                        return SqlExecTool.GetRow<val, Result>(this._TableName, this.MyDAL, column, value);
                }
                protected T GetRow<T>(string orderBy, params ISqlWhere[] where)
                {
                        return SqlExecTool.GetRow<T>(this._TableName, this.MyDAL, orderBy, where);
                }
                protected T GetRowTable<T>(string table, params ISqlWhere[] where)
                {
                        return SqlExecTool.GetRow<T>(table, this.MyDAL, where);
                }
                #endregion

                #region 单列查询(ExecuteScalar)

                protected T ExecuteScalarTable<T>(string table, string column, T def, params ISqlWhere[] where)
                {
                        return SqlExecTool.ExecuteScalarDef<T>(table, this.MyDAL, column, def, where);
                }
                protected T ExecuteScalarTable<T>(string table, string column, params ISqlWhere[] where)
                {
                        return SqlExecTool.ExecuteScalar<T>(table, this.MyDAL, column, where);
                }
                protected T ExecuteScalar<T>(string column, params ISqlWhere[] where)
                {
                        return SqlExecTool.ExecuteScalar<T>(this._TableName, this.MyDAL, column, where);
                }
                protected T ExecuteScalar<T, Val>(string column, string where, Val value)
                {
                        return SqlExecTool.ExecuteScalar<T, Val>(this._TableName, this.MyDAL, column, where, value);
                }
                protected T ExecuteScalarSort<T>(string column, string orderBy, params ISqlWhere[] where)
                {
                        return SqlExecTool.ExecuteScalarSort<T>(this._TableName, this.MyDAL, column, orderBy, where);
                }
                protected T ExecuteScalar<T>(string column, SqlFuncType func, params ISqlWhere[] where)
                {
                        return SqlExecTool.ExecuteScalar<T>(this._TableName, this.MyDAL, column, func, where);
                }
                protected T ExecuteScalar<T>(string column, string func, params ISqlWhere[] where)
                {
                        return SqlExecTool.ExecuteScalar<T>(this._TableName, this.MyDAL, column, func, where);
                }
                protected T ExecuteCount<T>(params ISqlWhere[] where) where T : struct
                {
                        return SqlExecTool.ExecuteScalar<T>(this._TableName, this.MyDAL, "*", SqlFuncType.count, where);
                }

                protected T ExecuteSum<T>(string column, params ISqlWhere[] where) where T : struct
                {
                        return SqlExecTool.ExecuteScalar<T>(this._TableName, this.MyDAL, column, SqlFuncType.sum, where);
                }
                protected bool CheckIsExists(params ISqlWhere[] where)
                {
                        return SqlExecTool.CheckIsExists(this._TableName, this.MyDAL, where);
                }
                #endregion

                #region 分组(Group by)
                protected T[] GroupOutColumn<T>(string table, string group, params ISqlWhere[] where)
                {
                        return SqlExecTool.GroupOutColumn<T>(table, this.MyDAL, group, where);
                }
                protected T[] GroupOutColumn<T>(string group, params ISqlWhere[] where)
                {
                        return SqlExecTool.GroupOutColumn<T>(this._TableName, this.MyDAL, group, where);
                }
                protected T[] Group<T>(string group, params ISqlWhere[] where)
                {
                        return this.Group<T>(new string[] { group }, where);
                }
                protected Result[] Group<T, Result>(string group, string column, T[] ids, params ISqlWhere[] where)
                {
                        return SqlExecTool.Group<T, Result>(this._TableName, this.MyDAL, new string[] { group }, column, ids, where);
                }
                protected T GroupOutRow<T>(string group, params ISqlWhere[] where)
                {
                        return this.GroupOutRow<T>(new string[] { group }, where);
                }
                protected T[] Group<T>(string group, string orderBy, params ISqlWhere[] where)
                {
                        return this.Group<T>(new string[] { group }, orderBy, where);
                }
                protected T[] Group<T>(string[] groups, params ISqlWhere[] where)
                {
                        return SqlExecTool.Group<T>(this._TableName, this.MyDAL, groups, where);
                }
                protected T GroupOutRow<T>(string[] groups, params ISqlWhere[] where)
                {
                        return SqlExecTool.GroupOutRow<T>(this._TableName, this.MyDAL, groups, where);
                }
                protected T[] Group<T>(string[] groups, string orderBy, params ISqlWhere[] where)
                {
                        return SqlExecTool.Group<T>(this._TableName, this.MyDAL, groups, orderBy, where);
                }
                protected T[] GroupQuery<T>(string[] groups, int index, int size, string orderBy, out long count, params ISqlWhere[] where)
                {
                        return SqlExecTool.GroupQuery<T>(this._TableName, this.MyDAL, groups, index, size, orderBy, out count, where);
                }
                protected T[] GroupQuery<T>(string group, int index, int size, string orderBy, out long count, params ISqlWhere[] where)
                {
                        return SqlExecTool.GroupQuery<T>(this._TableName, this.MyDAL, new string[] { group }, index, size, orderBy, out count, where);
                }
                protected T[] GroupOutColumn<T>(string group, int index, int size, string orderBy, out long count, params ISqlWhere[] where)
                {
                        return SqlExecTool.GroupQuery<T>(this._TableName, this.MyDAL, group, index, size, orderBy, out count, where);
                }
                #endregion

                #region 分组查询(Group by having)

                protected T[] GroupOutColumn<T>(string group, ISqlWhere[] having, params ISqlWhere[] where)
                {
                        return SqlExecTool.GroupOutColumn<T>(this._TableName, this.MyDAL, group, having, where);
                }
                protected T[] Group<T>(string group, ISqlWhere[] having, params ISqlWhere[] where)
                {
                        return SqlExecTool.Group<T>(this._TableName, this.MyDAL, group, having, where);
                }
                protected T[] Group<T>(string group, string orderBy, ISqlWhere[] having, params ISqlWhere[] where)
                {
                        return SqlExecTool.Group<T>(this._TableName, this.MyDAL, group, orderBy, having, where);
                }
                protected T[] Group<T>(string[] groups, ISqlWhere[] having, params ISqlWhere[] where)
                {
                        return SqlExecTool.Group<T>(this._TableName, this.MyDAL, groups, having, where);
                }
                protected T[] Group<T>(string[] groups, string orderBy, ISqlWhere[] having, params ISqlWhere[] where)
                {
                        return SqlExecTool.Group<T>(this._TableName, this.MyDAL, groups, orderBy, having, where);
                }
                protected T GroupOutRow<T>(string group, ISqlWhere[] having, params ISqlWhere[] where)
                {
                        return SqlExecTool.GroupOutRow<T>(this._TableName, this.MyDAL, group, having, where);
                }
                #endregion


                #region 链接查询
                public T[] UnionQuery<T>(string column, UnionQueryParam[] unions, params ISqlWhere[] where)
                {
                        return SqlExecTool.UnionQuery<T>(this.MyDAL, column, unions.Add(new UnionQueryParam
                        {
                                Table = _TableName,
                                Where = where
                        }));
                }
                public Result[] UnionQuery<T, Result>(string column, T[] ids, params ISqlWhere[] where)
                {
                        UnionQueryParam[] list = ids.ConvertAll(a =>
                       {
                               ISqlWhere t = new SqlWhere(column, SqlToolsHelper.GetSqlDbType(typeof(T))) { Value = a };
                               where = where.Add(t);
                               return new UnionQueryParam
                               {
                                       Table = _TableName,
                                       Where = where
                               };
                       });
                        return SqlExecTool.UnionQuery<Result>(this.MyDAL, list);
                }
                public T UnionRow<T>(UnionParam[] where, string orderFieId, bool isAsc)
                {
                        return SqlExecTool.UnionRow<T>(this.MyDAL, where.ConvertAll(a => new UnionQueryParam
                        {
                                OrderBy = a.OrderBy,
                                Table = this._TableName,
                                TopNum = a.TopNum,
                                Where = a.Where
                        }), orderFieId, isAsc);
                }
                public Result[] UnionQuery<T, Result>(string column, T[] ids, string orderBy, int top, params ISqlWhere[] where)
                {
                        UnionQueryParam[] list = ids.ConvertAll(a =>
                       {
                               ISqlWhere t = new SqlWhere(column, SqlToolsHelper.GetSqlDbType(typeof(T))) { Value = a };
                               where = where.Add(t);
                               return new UnionQueryParam
                               {
                                       Table = _TableName,
                                       Where = where,
                                       OrderBy = orderBy,
                                       TopNum = top
                               };
                       });
                        return SqlExecTool.UnionQuery<Result>(this.MyDAL, list);
                }
                public T[] UnionQuery<T>(UnionQueryParam[] query) where T : class
                {
                        return SqlExecTool.UnionQuery<T>(this.MyDAL, query);
                }
                public T[] UnionQuery<T>(ISqlWhere[] one, ISqlWhere[] two) where T : class
                {
                        return SqlExecTool.UnionQuery<T>(this.MyDAL, new UnionQueryParam[] {
                                new UnionQueryParam
                                {
                                        Table = _TableName,
                                        Where = one
                                },new UnionQueryParam
                                {
                                        Table = _TableName,
                                        Where = two
                                }
                        });
                }
                public T[] UnionQuery<T>(string column, ISqlWhere[] one, ISqlWhere[] two)
                {
                        return SqlExecTool.UnionQuery<T>(this.MyDAL, column, new UnionQueryParam[] {
                                new UnionQueryParam
                                {
                                        Table = _TableName,
                                        Where = one
                                },new UnionQueryParam
                                {
                                        Table = _TableName,
                                        Where = two
                                }
                        });
                }
                #endregion

                public bool TableIsExists(string table)
                {
                        string sql = string.Format("select top 1 [name] from sys.objects where object_id = OBJECT_ID(N'{0}') AND type in (N'U')", table);
                        string name = SqlExecTool.ExecuteScalar<string>(sql, this.MyDAL);
                        return name == table;
                }
                public void Dispose()
                {
                        this.MyDAL.Dispose();
                }
        }
}